package com.ruijiang.service.VmService.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ruijiang.dto.insert.PolicyInsertDto;
import com.ruijiang.dto.page.PageBaseDto;
import com.ruijiang.dto.page.PagePolicyDto;
import com.ruijiang.entity.Policy;
import com.ruijiang.mapper.VmServiceMapper.PolicyMapper;
import com.ruijiang.mapper.VmServiceMapper.VmMapper;
import com.ruijiang.result.PageResult;
import com.ruijiang.service.VmService.PolicyService;
import com.ruijiang.vo.policy.PolicyVMVO;
import com.ruijiang.vo.vm.VMNodeNameVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class PolicyServiceImpl implements PolicyService {

    @Autowired
    private PolicyMapper policyMapper;
    @Autowired
    private VmMapper vmMapper;

    /**
     * 查询策略列表
     * @param dto
     * @return
     */
    @Override
    public PageResult getList(PagePolicyDto dto) {
        PageHelper.startPage(dto.getPageIndex(),dto.getPageSize());
        Page page = (Page) policyMapper.getList(dto);
        return PageResult.pageBuild(page);
    }

    /**
     * 删除策略
     * @param policyId
     */
    @Override
    public void deletePolicyById(String policyId) {
        policyMapper.deletePolicyById(policyId);
    }

    /**
     * 新增策略
     * @param dto
     */
    @Override
    public void insertPolicy(PolicyInsertDto dto) {
        policyMapper.insertPolicy(dto);
    }

    /**
     * 查询售货机策略
     * @param innerCode
     * @return
     */
    @Override
    public PolicyVMVO getPolicyByInnerCode(String innerCode) {
        return policyMapper.getPolicyByInnerCode(innerCode);
    }

    @Override
    public PageResult getVMByPolicy(String policyId, PageBaseDto dto) {
        PageHelper.startPage(dto.getPageIndex(),dto.getPageSize());
        Page page = (Page) vmMapper.getVMByPolicy(policyId,dto);
        return PageResult.pageBuild(page);
    }

    /**
     * 修改策略
     *
     * @param policyId
     * @param dto
     */
    @Override
    public void updatePolicyById(String policyId, PolicyInsertDto dto) {
        policyMapper.updatePolicyById(policyId,dto);
    }


}
